package com.cos.hospital.ui.record.adapter;

import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cos.hospital.R;
import com.cos.hospital.ui.record.RecordCode;
import com.cos.hospital.ui.record.bean.BeanFormula;

import java.util.List;

/**
 * @Description: 公式
 * @Author: Kosmos
 * @Date: 2018年09月22日 20:52
 * @Email: KosmoSakura@foxmail.com
 */
public class AdapterFormula extends BaseQuickAdapter<BeanFormula, BaseViewHolder> {

    public AdapterFormula(@Nullable List<BeanFormula> data) {
        super(R.layout.item_formula, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BeanFormula item) {
        TextView tName = helper.getView(R.id.formula_name);
        ImageView showOne = helper.getView(R.id.formula_1);
        ImageView showTwo = helper.getView(R.id.formula_2);
        switch (item.getFormulaId()) {
            case RecordCode.FormulaId.FID_LMP_1://月经史:
            case RecordCode.FormulaId.FID_LMP_2://月经史:
                tName.setText("月经史");
                showTwo.setVisibility(View.VISIBLE);
                showOne.setImageResource(R.mipmap.ic_formula_yue_1);
                showTwo.setImageResource(R.mipmap.ic_formula_yue_2);
                break;
            case RecordCode.FormulaId.FID_GP://孕产史:
                tName.setText("孕产史");
                showTwo.setVisibility(View.GONE);
                showOne.setImageResource(R.mipmap.ic_formula_yuchan);
                break;
            case RecordCode.FormulaId.FID_Birth://生育史:
                tName.setText("生育史");
                showTwo.setVisibility(View.GONE);
                showOne.setImageResource(R.mipmap.ic_formula_shengyu);
                break;
        }
        helper.addOnClickListener(R.id.formula_1);
        helper.addOnClickListener(R.id.formula_2);
        helper.getView(R.id.formula_root).setOnTouchListener((view, event) -> {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                tName.setTextColor(ContextCompat.getColor(helper.itemView.getContext(), R.color.green_txt));
                return true;
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                tName.setTextColor(ContextCompat.getColor(helper.itemView.getContext(), R.color.gray_txt_deep));
                view.performClick();
                return true;
            } else return false;
        });
    }
}
